package cn.kgc.controller;

import cn.kgc.bean.pojo.EpStaff;
import cn.kgc.bean.pojo.StRisk;
import cn.kgc.bean.vo.Result;
import cn.kgc.service.EpStaffService;
import cn.kgc.service.StRiskService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @projectName: safetyMag
 * @package: cn.kgc.controller
 * @className: StRiskController
 * @author: yindexin
 * @description: TODO
 * @date: 2023/5/1 16:38
 * @version: 1.0
 */
@RestController
@RequestMapping("stRisk")
@Slf4j
public class StRiskController {

    @Resource
    private StRiskService stRiskService;
    @Resource
    private EpStaffService epStaffService;

    @RequestMapping("/getStRiskAll/{pageFrom}/{pageSize}")
    private Result getStRiskAll(@PathVariable Integer pageFrom,
                                @PathVariable Integer pageSize){
        PageHelper.startPage(pageFrom,pageSize);
        List<StRisk> list = stRiskService.getStRiskAll();
//        List<EpStaff> list1 = epStaffService.getAllInfoEpStaff();
//        int num = 0;
//        for (int i = 0; i < list1.size(); i++){
//            num +=list1.get(i).getViolate();
//        }
//        PageInfo pageInfo = new PageInfo<>(list);
//        log.info("总条数：" +pageInfo.getTotal());
//        log.info("违章次数：" +num);
        PageInfo pageInfo = new PageInfo<>(list);
        return Result.success(pageInfo);
    }
    @RequestMapping("/getCount")
    private Result getCount(){
        List<StRisk> list = stRiskService.getStRiskAll();
        List<EpStaff> list1 = epStaffService.getAllInfoEpStaff();

        int num = 0;
        for (int i = 0; i < list1.size(); i++){
            num +=list1.get(i).getViolate();
//            System.out.println(num+"---------------------");
        }
        PageInfo pageInfo = new PageInfo<>(list);
        log.info("总条数：" +pageInfo.getTotal());
        log.info("违章次数：" +num);
        return Result.success(num);
    }


}
